{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 训练\n",
    "https://github.com/qqwweee/keras-yolo3\n",
    "\n",
    "\n",
    "Python 3.5.2\n",
    "\n",
    "Keras 2.1.5\n",
    "\n",
    "tensorflow 1.6.0\n",
    "\n",
    "\n",
    "### Test\n",
    "\n",
    "```\n",
    "wget https://pjreddie.com/media/files/yolov3.weights\n",
    "python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5\n",
    "python yolo_video.py [OPTIONS...] --image, for image detection mode, OR\n",
    "python yolo_video.py [video_path] [output_path (optional)]\n",
    "```\n",
    "For Tiny YOLOv3, just do in a similar way, just specify model path and anchor path with --model model_file and --anchors anchor_file.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## yolo - voc 自带的模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2.1.5'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import keras\n",
    "keras.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5   # 预测的时候用\n",
    "#!python convert.py -w yolov3.cfg yolov3.weights model_data/yolo_weights.h5  #  训练的时候用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model_data/yolo.h5 model, anchors, and classes loaded.\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "import argparse\n",
    "from yolo import YOLO, detect_video\n",
    "from PIL import Image\n",
    "\n",
    "yolo_test_args = {\n",
    "    \"model_path\": 'model_data/yolo.h5',\n",
    "    \"anchors_path\": 'model_data/yolo_anchors.txt',\n",
    "    \"classes_path\": 'model_data/coco_classes.txt',\n",
    "    \"score\" : 0.3,\n",
    "    \"iou\" : 0.45,\n",
    "    \"model_image_size\" : (416, 416),\n",
    "    \"gpu_num\" : 1,\n",
    "}\n",
    "\n",
    "\n",
    "yolo_test = YOLO(**yolo_test_args)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(416, 416, 3)\n",
      "Found 1 boxes for img\n",
      "person 1.00 (0, 40) (440, 743)\n",
      "4.213498038239777\n"
     ]
    }
   ],
   "source": [
    "image = Image.open('images/part1/1.00_tableksf_1000002-3.jpg')\n",
    "r_image = yolo_test.detect_image(image)\n",
    "r_image.show()\n",
    "#yolo.close_session()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
